package gamesrv.server;

import java.lang.management.ManagementFactory;

import javax.management.*;

import gamesrv.api.GameServer;
import gamesrv.server.impl.GameServerImpl;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;

public class Activator implements BundleActivator {

	
	ServiceRegistration<?> srvToken;
		
		
	public void start(BundleContext context) throws Exception {
		System.out.println("Game server: starting..");
					
		
		GameServer gameServer = new GameServerImpl(context);
		
		
		 MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); 
	     //ObjectName jmxname = new ObjectName("gamesrv.server:type=GameServerImpl"); 	      
	     //mbs.registerMBean(gameServer, jmxname); 
		
		srvToken = context.registerService(GameServer.class, gameServer, null);
		System.out.println("Game service: started.");
	}
	
	
	public void stop(BundleContext context) throws Exception {
		System.out.println("Game service: stopping..");
		srvToken.unregister();		
		System.out.println("Game service: stopped..");
	}
}
